package com.example.administrator.u17.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.example.administrator.u17.R;

public class WebViewActivity extends AppCompatActivity {

    private WebView webView;
    private String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_web_view);
        initView();
        initData();
        setListener();
    }

    private void setListener() {
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);
                return true;
            }
        });
//        webView.loadData();
    }

    private void initData() {
        Intent intent=getIntent();
        if (intent!=null){
            url = intent.getStringExtra("url");
        }
        webView.loadUrl(url);
    }

    private void initView() {
        webView=(WebView)findViewById(R.id.wv_activity_webView);
    }
}
